from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import Qt
from ui.main import Ui_MainWindow
from controller.main2 import MainWindow2
from controller.counter import CounterWindow


class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    mainWindow2: MainWindow2
    counterWindow: CounterWindow

    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)
        self.bt1.clicked.connect(self.click_pushButton_1)  # 点击 pushButton_1 触发
        self.bt2.clicked.connect(self.click_pushButton_2)  # 点击 pushButton_2 触发
        # 子窗口实例化
        self.mainWindow2 = MainWindow2()
        self.counterWindow = CounterWindow()

    # 点击 bt1 触发
    def click_pushButton_1(self):
        self.mainWindow2.showFullScreen()

        value = self.lineEdit.text()
        self.mainWindow2.dataPass(value)
        # self.counterWindow.dataPass(value)
        return

    # 点击 bt2 触发
    def click_pushButton_2(self):
        self.lineEdit.clear()
        return

    def keyPressEvent(self, event: QtGui.QKeyEvent):
        print("按下：" + str(event.key()))

        if (event.key() == 16777220):
            self.mainWindow2.showFullScreen()

            value = self.lineEdit.text()
            self.mainWindow2.dataPass(value)
            # self.counterWindow.dataPass(value)
            print('测试：Enter')
        if (event.key() == Qt.Key_Escape):
            self.lineEdit.clear()
            print('测试：Esc')
        if (event.key() == Qt.Key_F1):
            print('测试：F1')
            self.close()